Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ibc-core): reject packets with no timeouts in send_packet_validate #1205

Merged
merged 7 commits into from
May 2, 2024

Conversation

rnbguy
Copy link
Collaborator

@rnbguy rnbguy commented Apr 29, 2024

Closes: #1198

Description

send_packet_validate should reject packets that have neither timeout height nor timestamp.

Reference to ICS04 spec.


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests.
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

@rnbguy
Copy link
Collaborator Author

rnbguy commented Apr 29, 2024

Looks like these two tests (without any timeout) are expected to pass.

// Timeout packets
Test {
name: "Transfer message no timeout".to_string(),
msg: msg_transfer_no_timeout.into(),
want_pass: true,
state_check: None,
},
Test {
name: "Transfer message no timeout nor timestamp".to_string(),
msg: msg_transfer_no_timeout_or_timestamp.into(),
want_pass: true,
state_check: None,
},

Judging by the impl TryFrom<RawMsgTransfer> for MsgTransfer, this should have failed

if !timeout_height_on_b.is_set() && !timeout_timestamp_on_b.is_set() {
return Err(ContextError::from(PacketError::MissingTimeout))?;
}

@rnbguy rnbguy changed the title fix(ibc-core): send_packet_validate checks for timeouts fix(ibc-core): reject packets with no timeouts in send_packet_validate Apr 29, 2024
@@ -84,7 +84,7 @@ mod tests {

let proof_height = 10;
let default_raw_packet = dummy_raw_packet(proof_height, 1000);
let raw_packet_no_timeout_or_timestamp = dummy_raw_packet(10, 0);
let raw_packet_no_timeout_of_timestamp = dummy_raw_packet(10, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe?

Suggested change
let raw_packet_no_timeout_of_timestamp = dummy_raw_packet(10, 0);
let raw_packet_no_timeout_timestamp = dummy_raw_packet(10, 0);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +33 to +35
if !packet.timeout_height_on_b.is_set() && !packet.timeout_timestamp_on_b.is_set() {
return Err(ContextError::PacketError(PacketError::MissingTimeout));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we do a similar check in recv, timeout and timeoutOnClose?
All the on_a vs on_b cause a lot of duplicate code, ideally this check should be done in one place for all messages that include a packet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good question! Here's my argument:

  • OnRecvPacket: timeout doesn't matter - as this would generate packet_ack anyway.
  • OnTimeout/OnTimeoutClose: we added send_packet with timeout height or timeout timestamp (invariant).

Also, I didn't find these checks in IBC spec and in ibc-go.

@seanchen1991 seanchen1991 marked this pull request as ready for review May 1, 2024 20:10
Copy link

codecov bot commented May 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.45%. Comparing base (30a295c) to head (f2c1a42).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1205      +/-   ##
==========================================
+ Coverage   64.44%   64.45%   +0.01%     
==========================================
  Files         229      229              
  Lines       22051    22055       +4     
==========================================
+ Hits        14210    14215       +5     
+ Misses       7841     7840       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rnbguy rnbguy added this pull request to the merge queue May 2, 2024
Merged via the queue into main with commit 87ec770 May 2, 2024
19 checks passed
@rnbguy rnbguy deleted the rano/fix/1198 branch May 2, 2024 11:33
Farhad-Shabani pushed a commit that referenced this pull request Sep 9, 2024
…te` (#1205)

* correct name

* add test for packet with no timeout

* ensure packet timeout is set

* rename var

* fix test compile

* packet without timeout should fail

---------

Co-authored-by: Sean Chen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Packet timeout isn’t checked when sending
3 participants